Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support runtime Topic designation #44

Merged
merged 1 commit into from
Nov 8, 2023
Merged

Support runtime Topic designation #44

merged 1 commit into from
Nov 8, 2023

Conversation

rnarubin
Copy link
Collaborator

Previously the Topic type was only constructible from static strings. This works for code-gen messages, but doesn't work if the topic needs to be determined at runtime. This change permits constructing Topics from arbitrary strings

@rnarubin rnarubin self-assigned this Sep 21, 2023
@rnarubin
Copy link
Collaborator Author

@blogle

pub struct Topic(&'static str);
// A survey of common topics found lengths between 16 and 35 bytes
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Topic(SmallString<[u8; 36]>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did run into this problem, since I am creating topic names dynamically - but worked around it by leaking the strings and then using a hashmap to cache the mapping from (site id, prio) -> &'static str

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there's a reasonable bound on that combination, so that's not the worst. But we can do better!

TopicSink::new(
client.client.publish_topic_sink(
TopicName::new(topic.as_ref())
.into_project_topic_name(client.project()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular line is what I think needs to change for me to send messages across various projects. Though you might be wanting to address that in a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, different PR

pub struct Topic(&'static str);
// A survey of common topics found lengths between 16 and 35 bytes
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Topic(SmallString<[u8; 36]>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this saying we can support any string up to 36Bytes? I wonder if any of our topics exceed that? Or is this similar to a stackvec and will falback to heap allocation if we exceed that threshold?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's backed by SmallVec, which yeah does the fallback to heap

Previously the Topic type was only constructible from static strings.
This works for code-gen messages, but doesn't work if the topic needs to
be determined at runtime. This change permits constructing Topics from
arbitrary strings
@rnarubin rnarubin merged commit e96fb3c into master Nov 8, 2023
5 checks passed
@rnarubin rnarubin deleted the runtime_topic branch November 8, 2023 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants